<ul class="breadcrumb">
  <li><a href="<?= site_url('user/tasks/projects_details')?>">All Projects</a> <span class="divider">/</span></li>
  <li><a href="<?= site_url('user/tasks/milestones_details').'/'.$tasks['project_id'] ?>"><?= $tasks['name']; ?></a> <span class="divider">/</span></li>
  <li><?php  
  $task = $this->common_model->get_taskgroupname_by_id($tasks['taskgroup_id']);
  echo $task['name']
  ?><span class="divider">/</span></li>  
  <li class="active"><?= $tasks['title']; ?></li>
</ul>

<div class="row-fluid">
<div class="span10">
<table width="100%" class="table-condenesed">
<header><?= $tasks['title']; ?></header>
  <tr >
    <td colspan="2" valign="bottom">
    <small class="muted" id="completed"></small>
    <div class="progress progress-info progress-striped">
      <div class="bar" style="width:0%"></div>
  </div></td>
  <?php if(empty($subtasks)) {?>
    <td width="12%"><button type="button" class="btn" id="achieved">Achieved</button>
  </td>
  <?php }?>
    <td width="11%"><a href="#" class="btn" id="closed">Close</a></td>
  </tr>
  <tr>
    <td width="49%" height="37"><strong>Final Due Date :</strong>  <?=$tasks['end_date'];?></td>
    <td colspan="2"><strong>Assigned to : </strong>
   <?php
	$username = $this->common_model->get_username_id($tasks['user_id']);
	echo $username['username'];
	?>
    </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Task Description</strong></td>
    <td width="28%">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="4"><?= $tasks['desc']?></td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>

</table>
<h5>Subtasks <span class="badge badge-info" id="subtask">
<?php $count = 0;
foreach($subtasks as $subtask)
{
if($subtask->is_heading==0){
	$count = $count+1;
}
}
echo $count;
?>
</span></h5>


 <div id="contentLeft">
<ul class="ui-sortable" style="list-style:none;margin:0;">
<?php
if(empty($subtasks))
{?>
No Subtask has been added 
<?php }
else {
$i = 0;	
?>
<?php foreach($subtasks as $subtask){?>
<li id="recordsArray_<?= $subtask->id?>" class="<?php echo ($subtask->is_achieved==1)? 'achieved_pattern':''?>"  >
<div class="row-fluid <?php if($subtask->is_heading==0){?>borders <?php }?>">

<div class="span10">

<?php if($subtask->is_heading==0){?>
<div class="flag_image tooltips <?php if($subtask->is_achieved=='0'){if(!$subtask->priority) { echo "none";} else {echo $subtask->priority;}} ?>" data-toggle="tooltip" title="Click and Drag for Reordering subtasks" data-placement="left" >

<div><?= $i=$i+1;?></div>
</div>  
<?php  } else {?>

<div class="flag_image tooltips subtask_heading" data-toggle="tooltip" title="Click and Drag for Reordering subtasks" data-placement="left" >
<?= $subtask->desc?>&nbsp;
<span class="subtask_heading_edit">
<a href="<?=site_url('user/tasks/delete_subheading/'.$subtask->id.'/'.$tasks['id'])?>" onclick="return confirm('Are you sure you Delete Press [Cancel] not to delete.')"><i class="icon-trash"></i></a>
</span>
</div>
<?php }?>
<input type="hidden" value="<?=$subtask->id?>" id="subtask_id<?=$subtask->id?>" />
<?php if($subtask->is_heading==0){?>
<?= $subtask->desc?>
<?php }?>
</div>
<div class="span1">
<?php if($subtask->is_heading==0){?>

<a id="<?= $subtask->id?>" onclick="achieve(this.id)" style="cursor:pointer" class="tooltips" data-toggle="tooltip" title="<?= $subtask->priority?>" data-placement="top">Pending</a></div>
<div class="span1">
<a href="<?=site_url('user/tasks/edit_subtask/'.$subtask->id)?>" title="Edit - <?= $subtask->desc?>" class="edit_subtasks tooltips" data-toggle="tooltip"><i class="icon-edit"></i></a> 
<?php if($this->session->userdata('user_id') == $subtask->user_id) {?>
<a href="<?=site_url('user/tasks/delete_subtask/'.$tasks['id'].'/'.$subtask->id)?>" data-toggle="tooltip" data-placement="right" class="tooltips" title="Delete - <?= $subtask->desc?>" onclick="return confirm('Are you sure you Delete Press [Cancel] not to delete.')" ><i class="icon-trash"></i></a>
<?php }?>
</div>
</div>
</li> 
<?php } } }?>
 </ul>
</div>
<!-- Drag n drop code ends here -->

<br />
<br />

<div class="well">
<h5><i class="icon-comments icon-large"></i>  Add Note to this Task</h5>
<small>You might enter a note about a call, or a meeting, or a conversation you just had with this person. Notes are great for keeping a history of your interactions or communications with someone.</small>
<br />
<br />

<label>
<textarea rows="5" cols="5" class="span12" name="note" id="note"></textarea>
<span class="text-error"><?=form_error('note')?></span>
</label>
<input type="hidden" value="<?=$task_id?>" name="task_id" id="task_id" />
<br />
<input type="button" value="Add Note" class="pull-right"  id="submit_note" />

</div>
<?php if($this->session->flashdata('note_message')) {?>
<div id="alert" class="alert alert-success">
<?= $this->session->flashdata('note_message') ?>
</div>
<?php }?>


<div>
<?php if(empty($notes)) {?>
<small >No Notes Till Now</small>
<?php } else {?>
<table width="100%" class="">
<?php foreach($notes as $note) {?>
  <tr>
    <td width="10%" rowspan="3" valign="top">
    <?php if(!$note->profile_image) {?>
    <img class="img-polaroid" width="48" src="<?= $this->config->base_url(); ?>assets/images/users.png" />    
	<?php } else {?>
    <img class="img-polaroid" width="48" src="<?= $this->config->base_url(); ?>assets/uploads/<?= $note->profile_image?>" />
    
	<?php }?>
    
    </td>
    <td width="90%"><strong>Note by</strong> : <?= $note->username;?>
    <?php if($note->user_id == $this->session->userdata('user_id')) {?>
    <a href="<?= site_url('user/tasks/delete_note').'/'.$note->id.'/'.$tasks['id'];?>"><i class="icon-trash pull-right"></i></a>
    <?php }?>
    </td>
  </tr>
  <tr>
    <td class="muted">on <?= $note->date?></td>
  </tr>
  <tr>
    <td><?= $note->note?></td>
  </tr>
  <tr>
  <td>&nbsp;</td>
   <td>&nbsp;</td>
  
  </tr>
<?php } ?>
</table>
<?php }?>
</div>
</div>
<div class="span2">
<header><i class="icon-cog"></i> Actions</header>
<i class="icon-plus"></i> <a href="#myModal" role="button" data-toggle="modal">Add New Sub Taks</a>
<br />
<i class="icon-plus-sign"></i> <a href="#subtask_heading" role="button" data-toggle="modal">Add Subtask Heading</a>
<br />

<i class="icon-pencil"></i> <a href="<?= site_url('user/tasks/edit').'/'.$tasks['id']?>">Edit this Task</a>
<br />
 <?php if($tasks['user_id'] == $this->session->userdata('user_id')) {?>
<i class="icon-trash"></i> <a href="<?= site_url('user/tasks/delete_task').'/'.$tasks['id'].'/'.$tasks['milestone_id']?>" onclick="return confirm('Are you sure you want to DELETE this task ??')">Delete This Task</a>
<?php }?>
</div>
</div>

<!-- Sub tasks -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <?= form_open('user/tasks/create_subtask/'.$tasks['id'])?>
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Add New Sub Task</h3>
  </div>
  <div class="modal-body">
    <p>   
    <textarea placeholder="Add New Sub Task" class="span12" name="subtask" ></textarea>    
    </p>
   <table width="100%">
   <tr>
    <td width="10%">Priority</td>
    <td width="10%">
     <label class="radio"><input type="radio" id="radioBtn4" onmouseup="toggle(this);" value="low" name="priority" /><span class="low_box"></span></label>
     </td>
     <td width="10%">
    <label class="radio"><input type="radio" id="radioBtn5" onmouseup="toggle(this);" value="medium" name="priority" /><span class="medium_box"></span></label>
    </td>    
    <td width="10%">
    <label class="radio"><input type="radio" id="radioBtn6" onmouseup="toggle(this);" value="high" name="priority" /><span class="high_box"></span></label>
    </td>
    </tr>
    </table>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-info" type="submit">Save changes</button>
    </form>
  </div>
</div>

<!-- Subtasks Heading -->
<div id="subtask_heading" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <?= form_open('user/tasks/create_subtask_heading/'.$tasks['id'])?>
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Add New Subtask Heading</h3>
  </div>
  <div class="modal-body">
    <p>   
    <textarea placeholder="Add New Subtask Heading" class="span12" name="subtask"></textarea>    
    </p>
  
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-info" type="submit">Save changes</button>
    </form>
  </div>
</div>

<script type="text/javascript">


$(document).ready(function(e) {
	// drag n drop	
	jQuery(function() {
		//alert("asdds");
		jQuery("#contentLeft ul").sortable({  handle: '.flag_image', opacity: 0.6, cursor: 'move',  update: function() {			
			var order = jQuery(this).sortable("serialize") + '&action=updateRecordsListings'; 
			//alert(order);
			jQuery.post("<?= site_url('user/tasks/sorting_subtasks');?>", order, function(theResponse){
				alert(theResponse);
			}); 															 
		}								  
		});});
   //$('#completed').html("0% Completed");
   var task_id = $('#task_id').val();	
	$.post('<?= site_url('user/tasks/check_is_achieved');?>',{taskid : task_id }, function(data) {
	// alert(data)
	 if(data == 1)
	 {
	$('.bar').css('width','100%');
	$('#completed').html("100% Completed");
	$('#achieved').addClass('btn-success')
	$('#achieved').html('Unachieved'); 	 
	 }
	 else { $('#completed').html("0% Completed");} 
});

$.post('<?= site_url('user/tasks/check_is_completed');?>',{taskid : task_id }, function(msg) {
	// alert(msg)
	 if(msg == 1)
	 {
	$('.bar').css('width','100%');
	$('#completed').html("100% Completed");
	$('#closed').addClass('btn-success')
	$('#closed').html('Open');
	$('#achieved').hide();	 
	 }
	 else { $('#completed').html("0% Completed");} 
});

//check subtask is achieved or not 
var subtasks = $('#subtask').html();

var subtasks_heading = <?= count($subtasks)?> - subtasks ;
//alert(subtasks_heading)
var comnpleted_percentage =  Math.round(100 / subtasks) ;
//alert(comnpleted_percentage);
var completed_value = 0;
var checkcompleted = 0;
var checknotcompleted = -subtasks_heading;
var total_subtask_completed = 0;
<?php foreach ($subtasks as $subt) {?>
var subtask_id = $('#subtask_id<?= $subt->id?>').val()
//alert(subtask_id)
$.post('<?= site_url('user/tasks/check_subtask_is_achieved');?>',{subtask_id  : subtask_id }, function(subtask_msg) {
	// alert(subtask_msg)
	
	 if(subtask_msg==1)
	 {
		total_subtask_completed = total_subtask_completed + 1;				 			
	completed_value = parseInt(comnpleted_percentage) +parseInt( completed_value);	
	//alert(completed_value);
		$('#<?= $subt->id?>').html('Achieved');
		$('#<?= $subt->id?>').addClass('text-success')
		$('#<?= $subt->id?>').css('font-weight','bold');
		$('.bar').css('width',completed_value+'%');
		$('#completed').html(completed_value +"% Completed");		
		//checkcompleted = 0;
		
		// adding the completed %
		//alert(completed_value)
		$.post('<?= site_url('user/tasks/completed_percentage');?>',{comp:completed_value,id:task_id}, function(completed) {
			//alert(completed)
			// location.reload(); 
		})
		
		//alert (total_subtask_completed);
		if(total_subtask_completed == subtasks)
		{
			$.post('<?= site_url('user/tasks/completed_percentage');?>',{comp:'100',id:task_id}, function(fullcompleted) {
			//alert(completed)
		})
			$('.bar').css('width','100%');
			$('#completed').html("100% Completed");	
		}
		
		
	 }
	// alert(completed_value);
	 else {		 
		 checknotcompleted  = (checknotcompleted + 1);
		 if(checknotcompleted == subtasks)	
		 {
			$.post('<?= site_url('user/tasks/completed_percentage');?>',{comp:'0',id:task_id}, function(notcompleted) {
			
		}) 
		 }
	 }
	
	

	
});


<?php }?>
;
//alert($('#completed').html())
/* if(checkcompleted == 0)
	 {
	$('.bar').css('width','100%');
	$('#completed').html("100% Completed");
	$.post('<?= site_url('user/tasks/task_achieved');?>',{taskid : task_id }, function(data) {
	// alert(data)
	$('.bar').css('width','100%');
	$('#completed').html("100% Completed");
	$('#achieved').addClass('btn-success')
	$('#achieved').html('Unachieved');	
	}); */
	// }
	//alert($('#completed').html());
	
});
// doucment ready function ends here


$('#submit_note').click(function () {	
	if(!$('#note').val())
	{
	alert('Note Feild is Required');	
	}
	else {
	var notes = $('#note').val();
	var task_id = $('#task_id').val();	
	$.post('<?= site_url('user/tasks/add_note');?>',{note : notes , taskid : task_id }, function(data) {
	//alert(data)
 $('#note').val("");
	  location.reload(); 
	 });
	}
	
	})

//Is Achieved
	
$('#achieved').click(function () {
	var task_id = $('#task_id').val();
	var check = $('#achieved').html();
	if( check == 'Unachieved' )
	{
	$.post('<?= site_url('user/tasks/task_unachieved');?>',{taskid : task_id }, function(data) {
	// alert(data)
	$('.bar').css('width','0%');
	$('#completed').html("0% Completed");
	$('#achieved').addClass('btn-primary')
	$('#achieved').html('Achieved');	
	});
	}
	//alert($('#achieved').html())
	else{	
	$.post('<?= site_url('user/tasks/task_achieved');?>',{taskid : task_id }, function(data) {
	// alert(data)
	$('.bar').css('width','100%');
	$('#completed').html("100% Completed");
	$('#achieved').addClass('btn-success')
	$('#achieved').html('Unachieved');	
	});
	}
})

$('#closed').click(function () {		
	var task_id = $('#task_id').val();
	var check = $('#closed').html();
	//alert(check);
	if( check == 'Open' )
	{
		//alert(check);
	$.post('<?= site_url('user/tasks/task_open');?>',{taskid : task_id }, function(data) {
	// alert(data)
	$('.bar').css('width','0%');
	$('#completed').html("0% Completed");
	$('#closed').addClass('btn-success')
	$('#closed').html('Close');	
	$('#achieved').show();
	});
	}
	else {
	$.post('<?= site_url('user/tasks/task_closed');?>',{taskid : task_id }, function(data) {
	// alert(data)
	$('.bar').css('width','100%');
	$('#completed').html("100% Completed");
	$('#closed').addClass('btn-success')
	$('#closed').html('Open');
	$('#achieved').hide(500); 
	});
	}
})
	
	function achieve(str)
	{
		var task_id = $('#task_id').val();
		var subtask_id = str;
		var subtasks = $('#subtask').html();
		var comnpleted_percentage =  parseInt(100 / subtasks) ;
		//alert(str);
		var id = "#"+str;
		if($(id).html() =='Achieved'){
		$.post('<?= site_url('user/tasks/subtask_unachieved');?>',{subtask_id : subtask_id }, function(data) {		
				location.reload();
});	
	}
	else {
$.post('<?= site_url('user/tasks/subtask_achieved');?>',{subtask_id : subtask_id }, function(data) {		
			location.reload();
});
	}
		}
		
		// subtasks edit scripts
		
$('.edit_subtasks').click(function(event) {	
  event.preventDefault();
  $.get(this.href, function(html) {
  $(html).appendTo('body').modal(); 
  });
});

function toggle(radioBtn)
 {   
   if(radioBtn.checked)
   {
     setTimeout("disableRadio('"+radioBtn.id+"')",10);
   } else {
     radioBtn.checked = true;
   }
 }

function disableRadio(radioId) {
    el = window.document.getElementById(radioId);
    el.checked = false;
}


$("#note").val(
    $.trim(
        $(this).closest('tr').next('tr')
            .find('.note').html().replace('<br/>', '/r/n')
    )
);		
</script>